package net.csdn.business.common.enums;

import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

/**
 * @author wanghang
 * @version 1.0
 * @date 2022/8/18 15:20
 */
@Getter
@AllArgsConstructor
public enum ActivityEnum {

    // 推送提交
    PUSHED(5, "push", "推送提交", ""),
    // 创建变更请求
    MERGE_CREATED(1, "created", "创建变更请求", ""),
    // Review变更请求
    MERGE_APPROVE(7, "approve", "Review变更请求", ""),
    // 合并代码
    MERGE_MERGED(13, "merge", "合并代码", ""),
    /**
     * filter 过滤条件 init里包含库创建 库导入 仓库同步 三个事件 (23.02.02 与云效确定)
     * 新建代码库
     */
    INIT_PROJECT(11, "init", "新建代码库", ""),
    IMPORT_PROJECT(12, "import", "库导入", ""),
    MIRROR_SYNC(18, "mirror_sync", "库同步", ""),
    // 代码库可见性变更（由私有库变更为公有库）
    OPENSOURCE_VISIBILITY(23, "公开仓库", "opensource_visibility", ""),

    ORG(21, "org", "创建组织", "CODE_EVENT_ORG"),
    ISSUE(22, "issue", "创建issue", "CODE_EVENT_ISSUE");

    /**
     * 需要获取仓库详情的类型
     */
    static final List<Integer> REPO_DETAIL_CODES = ImmutableList.of(PUSHED.getCode(), INIT_PROJECT.getCode(), IMPORT_PROJECT.getCode(), MIRROR_SYNC.getCode());

    /**
     * 字典值code
     */
    private final Integer code;
    /**
     * 字典值（英文）
     */
    private final String desc;
    /**
     * 字典描述（中文）
     */
    private final String descZn;
    /**
     * MQ发送对应tag（主要针对 org 和 issue）
     */
    private final String tag;

    public static List<Integer> getRepoDetailCodes() {
        return REPO_DETAIL_CODES;
    }

    public static ActivityEnum ofCode(Integer code) {
        for (ActivityEnum type : ActivityEnum.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("ActivityEnum param error");
    }

}